/*
 * Copyright 2013 Agustina Martinez-Garcia

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */
package uk.da.dext.datastructs;

import java.util.ArrayList;
import java.util.List;

public class CategoryStruct {
    
    private String categoryPid;
	
	private String categoryXmlId;
	/**
	 * Label of the category, value comes from 'value' field in spreadsheet
	 */
	private String categoryLabel;
	/**
	 * Display-label of the category, value comes from 'label' field in the spreadsheet
	 */
	private String categoryDisplayLabel;
	/**
	 * Holds a list of immediate children of a given category
	 */
	private List<String> immChildren;
	/**
	 * Holds a list of the immediate parents of a given category, not sure whether needed
	 */
	private List<String> immParents;
	/**
	 * Holds a list of the associated document references with a given category
	 * In this case each document reference will be the row number of the referenced document
	 * Shouldn't it has to be the document generated XML IDs?????
	 */
	private List<String> documentRefs;
	/**
	 * Documents XML IDs, not the Fedora PIDs, this is needed when generating the Qudex instances
	 */
	private List<String> documentRefsXmlIds;
	
	private String categoryLanguage;
	
	private boolean existingCategory;
	
	public void setImmParents(List<String> immParents) {
		this.immParents = immParents;
	}
	public List<String> getImmParents() {
		return immParents;
	}
	public void setImmChildren(List<String> immChildren) {
		this.immChildren = immChildren;
	}
	public List<String> getImmChildren() {
		return immChildren;
	}
	public void setCategoryDisplayLabel(String categoryDisplayLabel) {
		this.categoryDisplayLabel = categoryDisplayLabel;
	}
	public String getCategoryDisplayLabel() {
		return categoryDisplayLabel;
	}
	
	public void setCategoryLabel(String categoryLabel) {
		this.categoryLabel = categoryLabel;
	}
	public String getCategoryLabel() {
		return categoryLabel;
	}
	public void setDocumentRefs(List<String> documentRefs) {
		this.documentRefs = documentRefs;
	}
	public List<String> getDocumentRefs() {
		return documentRefs;
	}
	/**
	 * @param categoryXmlId the categoryXmlId to set
	 */
	public void setCategoryXmlId(String categoryXmlId) {
		this.categoryXmlId = categoryXmlId;
	}
	/**
	 * @return the categoryXmlId
	 */
	public String getCategoryXmlId() {
		return categoryXmlId;
	}
	
	/**
	 * @param documentRefsXmlIds the documentRefsXmlIds to set
	 */
	public void setDocumentRefsXmlIds(List<String> documentRefsXmlIds) {
		this.documentRefsXmlIds = documentRefsXmlIds;
	}
	/**
	 * @return the documentRefsXmlIds
	 */
	public List<String> getDocumentRefsXmlIds() {
		return documentRefsXmlIds;
	}
	public CategoryStruct(String label) {
		this.categoryLabel = label;
		this.documentRefs = new ArrayList<String>();
		this.immChildren = new ArrayList<String>();
		this.immParents = new ArrayList<String>();
		this.documentRefsXmlIds = new ArrayList<String>();
		this.categoryXmlId = "";
		this.categoryDisplayLabel = "";
		this.categoryLanguage = "";
		this.setExistingCategory(false);
	}
	/**
	 * Initialize all the structures of the category object
	 */
	public CategoryStruct() {
		this.documentRefs = new ArrayList<String>();
		this.immChildren = new ArrayList<String>();
		this.immParents = new ArrayList<String>();
		this.documentRefsXmlIds = new ArrayList<String>();
		this.categoryXmlId = "";
		this.categoryLabel = "";
		this.categoryDisplayLabel = "";
		this.categoryLanguage = "";
		this.setExistingCategory(false);
	}
	/**
	 * Add a new parent category to the array of parents of the given category
	 * @param parentCat name of the new parent category
	 */
	public void addCategoryParent(String parentCat) {
		//See if parent already present
		if (!this.immParents.contains(parentCat)) {
			this.immParents.add(parentCat);
		}
	}
	/**
	 * Add a new child category to the array of children of the given category
	 * @param childCat name of the new child category
	 */
	public void addCategoryChild(String childCat) {
		if (!this.immChildren.contains(childCat)) {
			this.immChildren.add(childCat);
		}
	}
	/**
	 * Locates a  parent within the list of parents of a particular category
	 * @param parent name of the parent to find
	 * @return true if element present
	 */
	public boolean findParent(String parent) {
		return this.immParents.contains(parent);
	}
	/**
	 * Finds a child within the list of children of a particular category
	 * @param child name of the child to find
	 * @return true if element present
	 */
	public boolean findChild(String child) {
		return this.immChildren.contains(child);
	}
	/**
	 * Finds a document reference within the list of document references of a particular category
	 * @param docRef name of the document reference to find
	 * @return true if element present
	 */
	public boolean findDocumentRef(String docRef) {
		return this.documentRefs.contains(docRef);
	}
	/**
	 * Clears all the elements from the lists managed by the category object:
	 * list of parents, list of children and list of document references
	 */
	public void clearCategoryLists() {
		this.immChildren.clear();
		this.immParents.clear();
		this.documentRefs.clear();
		this.documentRefsXmlIds.clear();
	}
	/**
	 * @param categoryLanguage the categoryLanguage to set
	 */
	public void setCategoryLanguage(String categoryLanguage) {
		this.categoryLanguage = categoryLanguage;
	}
	/**
	 * @return the categoryLanguage
	 */
	public String getCategoryLanguage() {
		return categoryLanguage;
	}
	/**
	 * @param categoryPid the categoryPid to set
	 */
	public void setCategoryPid(String categoryPid) {
	    this.categoryPid = categoryPid;
	}
	/**
	 * @return the categoryPid
	 */
	public String getCategoryPid() {
	    return categoryPid;
	}
	public boolean isExistingCategory() {
		return existingCategory;
	}
	public void setExistingCategory(boolean existingCategory) {
		this.existingCategory = existingCategory;
	}
}
